/**
 * 在这里定义和用户相关的路由处理函数，供 /router/user.js 模块进行调用
 */
const redis = require("../db/redis");

exports.set = (req, respond) => {
  const { key, value } = req.body
  redis.set(key, JSON.stringify(value), (err, res) => {
    if (err) {
      console.error('Error setting key:', err);
      return respond.cc("设置失败！");
    } else {
      console.log('Key set successfully:', res);
      respond.send({
        code: 200,
        message: '设置成功'
      })
    }
  });
};
exports.get = (req, respond) => {
  console.log(req.params.key);
  redis.get(req.params.key, (err, res) => {
    if (err) {
      console.error('Error getting key:', err);
      return respond.cc("取值失败！");
    } else {
      const value = JSON.parse(res)
      console.log('Key get successfully:', value);
      respond.send({
        code: 200,
        data: value
      })
    }
  });
};
